package com.qf.utils;


import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    @JsonIgnore
    private static final long serialVersionUID = -4983318455664415832L;
    /**
     * 业务状态码
     * 0, 表示操作成功
     * 非0, 表示操作失败
     */
    private int code;

    /**
     * 展示信息
     */
    private String msg;

    /**
     * 携带的数据
     */
    private Object data;

    private Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result success(int code, String msg, Object data) {
        return new Result(code, msg, data);
    }

    public static Result success(String msg, Object data) {
        return new Result(0, msg, data);
    }

    public static Result success(String msg) {
        return new Result(0, msg, null);
    }

    public static Result error(int code, String msg, Object data) {
        return new Result(code, msg, data);
    }

    public static Result error(String msg, Object data) {
        return new Result(-1, msg, data);
    }

    public static Result error(String msg) {
        return new Result(-1, msg, null);
    }
}